Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Empirical distribution #308

Merged
merged 8 commits into from
Dec 3, 2024

Conversation

FreezyLemon
Copy link
Contributor

Nothing here should be breaking. Some of the changes are opinionated code quality improvements.

Two noticeable improvements from this:

  • Struct size reduced (platform-dependent, but Option<(f64, f64)> is larger than two f64s. Up to 8 bytes on x64)
  • Avoids BTreeMap::remove inside fn remove if value > 1

Probably also removes a branch in fn add, but I honestly haven't checked the generated ASM or checked via benchmarking. Should I?

Copy link

codecov bot commented Nov 10, 2024

Codecov Report

Attention: Patch coverage is 97.56098% with 3 lines in your changes missing coverage. Please review.

Project coverage is 93.80%. Comparing base (252d3d7) to head (b604dbb).
Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
src/distribution/empirical.rs 97.56% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #308      +/-   ##
==========================================
+ Coverage   93.70%   93.80%   +0.10%     
==========================================
  Files          53       53              
  Lines       11939    12002      +63     
==========================================
+ Hits        11187    11259      +72     
+ Misses        752      743       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

The old code always removed entries and re-inserted them
if necessary. The new code will instead modify the value
(= data_point count) in-place and only remove the key-
value pair from the map if the count would've dropped to zero.
No value of `Infallible` can ever exist, so it is statically
proven that `Result<Empirical, Infallible>` can never exist
as a `Result::Err` variant. This allows layout optimizations
and is arguably a clearer API.
@FreezyLemon
Copy link
Contributor Author

Pushed a breaking change on top of the previous ones. Infallible is a useful type for this exact purpose, statically proves that no Err variant can ever exist of this result and allows a layout optimization (size_of::<Result<Empirical, Infallible>>() == size_of::<Empirical>())

@YeungOnion
Copy link
Contributor

It looks good, and the tests were definitely needed for the statistics. Thank you, I appreciate what you do.
TIL there's a way around not using nightly's !!

@YeungOnion YeungOnion merged commit 748aa55 into statrs-dev:master Dec 3, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants